# Maintainer: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
pkgname=opencv
pkgver=4.3.0
pkgrel=1
pkgdesc="An open source computer vision and machine learning library"
url="https://opencv.org"
arch="x86_64" # vtk missing on other platforms
license="BSD-3-Clause"
subpackages="$pkgname-dbg $pkgname-dev $pkgname-samples::noarch"
makedepends="
	blas-dev
	cmake
	eigen-dev
	ffmpeg-dev
	freetype-dev
	glew-dev
	gstreamer-dev
	harfbuzz-dev
	hdf5-dev
	lapack-dev
	libdc1394-dev
	libgphoto2-dev
	libtbb-dev
	mesa-dev
	openexr-dev
	openjpeg-dev
	openjpeg-tools
	py3-setuptools
	qt5-qtbase-dev
	vtk-dev
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/opencv/opencv/archive/$pkgver.tar.gz
	$pkgname-contrib-$pkgver.tar.gz::https://github.com/opencv/opencv_contrib/archive/$pkgver.tar.gz
	"
options="!check" # Tests require human interaction

build() {
	cmake -B build \
		-DWITH_OPENCL=ON \
		-DWITH_OPENGL=ON \
		-DWITH_TBB=ON \
		-DWITH_VULKAN=ON \
		-DWITH_QT=ON \
		-DBUILD_WITH_DEBUG_INFO=ON \
		-DBUILD_TESTS=OFF \
		-DBUILD_PERF_TESTS=OFF \
		-DBUILD_EXAMPLES=ON \
		-DINSTALL_C_EXAMPLES=ON \
		-DINSTALL_PYTHON_EXAMPLES=ON \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCPU_BASELINE_DISABLE=SSE3 \
		-DCPU_BASELINE_REQUIRE=SSE2 \
		-DOPENCV_EXTRA_MODULES_PATH="$srcdir/opencv_contrib-$pkgver/modules" \
		-DOPENCV_SKIP_PYTHON_LOADER=ON \
		-DOPENCV_GENERATE_PKGCONFIG=ON \
		-DOPENCV_ENABLE_NONFREE=ON \
		-DOPENCV_GENERATE_SETUPVARS=OFF \
		-DEIGEN_INCLUDE_PATH=/usr/include/eigen3 \
		-DLAPACK_LIBRARIES="/usr/lib/liblapack.so;/usr/lib/libblas.so;/usr/lib/libcblas.so" \
		.
	make -C build
}

check() {
	make -C build test
}

package() {
	make -C build DESTDIR="$pkgdir" install
}

samples() {
	pkgdesc="OpenCV Samples"
	depends="$pkgname=$pkgver"
	mkdir -p "$subpkgdir/usr/share/opencv4"
	mv "$pkgdir/usr/share/opencv4/samples" "$subpkgdir/usr/share/opencv4"
}

sha512sums="ac22b41fffa3e3138701fa0df0d19900b3ce72e168f4478ecdc593c5c9fd004b4b1b26612d62c25b681db99a8720db7a11b5b224e576e595624965fa79b0f383  opencv-4.3.0.tar.gz
cfeda06a9f86ccaedbca9521c35bf685c3d8d3a182fb943f9378a7ecd1949d6e2e9df1673f0e3e9686840ca4c9e5a8e8cf2ac962a33b6e1f88f8278abd8c37e5  opencv-contrib-4.3.0.tar.gz"
